package com.jdk8.lambda_02;

import java.security.PublicKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

public class PredicateDemo {

    public static <T> List<T> filter(List<T> list, Predicate<T> predicate) {
        ArrayList<T> arrayList = new ArrayList<>();
        for (T t : list) {
            if (predicate.test(t)) {
                arrayList.add(t);
            }
        }
        return arrayList;
    }

    public static void main(String[] args) {
        /*Predicate<String> predicate = new Predicate() {
            @Override
            public boolean test(Object o) {
                return false;
            }
        };*/

        List<String> list = Arrays.asList("aaa", "bbb", "ccc");
        List<String> filter = filter(list, (String str) -> !str.isEmpty());
        System.out.println(filter.toArray());
    }
}
